package com.hadoop.mr.writable;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.lib.db.DBWritable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by Administrator on 2019/7/11.
 */
public class CommentWritable implements Writable, DBWritable {

    private String nameTime;
    private String addTime;
    private Integer goodsCount;
    private String goodsName;
    private String goodsType;


    public CommentWritable() {
    }

    public String getAddTime() {
        return addTime;
    }

    public void setAddTime(String addTime) {
        this.addTime = addTime;
    }

    public String getNameTime() {
        return nameTime;
    }

    public void setNameTime(String nameTime) {
        this.nameTime = nameTime;
    }


    public Integer getGoodsCount() {
        return goodsCount;
    }

    public void setGoodsCount(Integer goodsCount) {
        this.goodsCount = goodsCount;
    }

    public String getGoodsType() {
        return goodsType;
    }

    public void setGoodsType(String goodsType) {
        this.goodsType = goodsType;
    }


    public CommentWritable(String nameTime, String addTime, String goodsName, Integer goodsCount, String goodsType) {
        this.nameTime = nameTime;
        this.goodsCount = goodsCount;
        this.addTime = addTime;
        this.goodsName = goodsName;
        this.goodsType = goodsType;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(addTime);
        out.writeInt(goodsCount);
        out.writeUTF(goodsName);
        out.writeUTF(goodsType);
    }


    @Override
    public void readFields(DataInput in) throws IOException {
        addTime = in.readUTF();
        goodsCount = in.readInt();
        goodsName = in.readUTF();
        goodsType = in.readUTF();
    }

    @Override
    public void write(PreparedStatement preparedStatement) throws SQLException {
        preparedStatement.setString(1, this.addTime);
        preparedStatement.setInt(2, new Double(this.goodsCount).intValue());
        preparedStatement.setString(3, this.goodsName);
        preparedStatement.setString(4, this.goodsType);
    }

    @Override
    public void readFields(ResultSet resultSet) throws SQLException {
        this.addTime = resultSet.getString(1);
        this.goodsCount = resultSet.getInt(2);
        this.goodsName = resultSet.getString(3);
        this.goodsType = resultSet.getString(4);
    }


}

